package cn.shangqizhenshuai.core;

import freemarker.template.TemplateException;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * 总执行器来执行任何执行器类型
 */
public  class  ExecuteCore extends Object implements Execute {
    public  Logger log = Logger.getLogger(this.getClass());
    //模板文件路径
    public String FTLname;
    //包名称
    public String packagename;
    //文件存放路径
    public String outFilePath;
    //全局文件信息
    public HashMap<String,List> context;
    //需要执行的子类
    public List<ExecuteCore> child;
    //是否需要 打开注解spring配置
    public boolean open_spring_annotate;

    public String getFTLname() {
        return FTLname;
    }

    public void setFTLname(String FTLname) {
        this.FTLname = FTLname;
    }

    public String getPackagename() {
        return packagename;
    }

    public void setPackagename(String packagename) {
        this.packagename = packagename;
    }

    public String getOutFilePath() {
        return outFilePath;
    }

    public void setOutFilePath(String outFilePath) {
        this.outFilePath = outFilePath;
    }

    public HashMap<String, List> getContext() {
        return context;
    }

    public void setContext(HashMap<String, List> context) {
        this.context = context;
    }

    public List<ExecuteCore> getChild() {
        return child;
    }

    public void setChild(List<ExecuteCore> child) {
        this.child = child;
    }

    public Logger getLog() {
        return log;
    }

    public void setLog(Logger log) {
        this.log = log;
    }

    public boolean isOpen_spring_annotate() {
        return open_spring_annotate;
    }

    public void setOpen_spring_annotate(boolean open_spring_annotate) {
        this.open_spring_annotate = open_spring_annotate;
    }

    public HashMap<String,List>  execute(HashMap<String,List> context) throws IOException, TemplateException {
        //获取所有字节点开始运行
        List<ExecuteCore> child = this.getChild();
        log.debug("开始执行过滤器链");
        for (ExecuteCore executeCore : child) {
            log.debug("开始执行"+executeCore.getClass().getSimpleName()+"执行器");
            this.setContext(executeCore.execute(this.getContext()));
        }
        return this.getContext();
    }


}
